/*
 * @Description: 弹框提示
 * @Version: V1.0.0
 * @Author: 黄鑫
 * @Date: 2024-12-10
 * @LastEditors: 黄鑫
 * @LastEditTime: 2025-11-12
 * @FilePath: BaseToast.dart
 * @Remarks: 
 */
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';

class BaseToast<T> {
  ///默认显示toast
  ///milliseconds 两秒消失
  ///isAutoDismiss 是否自动消失，当为false时，milliseconds失效,需要手动取消显示
  ///userInteractions 允许用户在加载中交互
  ///position 显示位置 默认上方
  static showToast<T>(T t,
      {int milliseconds = 2000,
      bool isAutoDismiss = true,
      bool userInteractions = true,
      EasyLoadingToastPosition position = EasyLoadingToastPosition.top}) {
    // 允许用户在加载中交互
    EasyLoading.instance.userInteractions = userInteractions;
    if (EasyLoading.isShow) {
      EasyLoading.dismiss();
    }
    EasyLoading.showToast(
      t.toString(),
      toastPosition: position,
      duration: isAutoDismiss
          ? Duration(milliseconds: milliseconds)
          : Duration(days: 1),
    );
  }

  ///显示toast 手动消失
  static show<T>([T? t, Widget? indicator]) {
    EasyLoading.instance.userInteractions = false;
    if (EasyLoading.isShow) {
      EasyLoading.dismiss();
    }
    EasyLoading.show(
      status: t?.toString(),
      indicator: CupertinoActivityIndicator(
        radius: 15,
        color: Colors.white,
      ),
    );
  }

  ///成功提示
  static showSuccess<T>(T t, {int milliseconds = 2000}) {
    EasyLoading.instance.userInteractions = true;
    if (EasyLoading.isShow) {
      EasyLoading.dismiss();
    }
    EasyLoading.showSuccess(t.toString(),
        duration: Duration(milliseconds: milliseconds));
  }

  ///失败提示
  static showError<T>(T t, {int milliseconds = 2000}) {
    EasyLoading.instance.userInteractions = true;
    if (EasyLoading.isShow) {
      EasyLoading.dismiss();
    }
    EasyLoading.showError(t.toString(),
        duration: Duration(milliseconds: milliseconds));
  }

  ///感叹号提示
  static showInfo<T>(T t, {int milliseconds = 2000}) {
    EasyLoading.instance.userInteractions = true;

    if (EasyLoading.isShow) {
      EasyLoading.dismiss();
    }
    EasyLoading.showInfo(t.toString(),
        duration: Duration(milliseconds: milliseconds));
  }

  ///取消显示
  static cancel() {
    EasyLoading.dismiss();
  }
}
